<template>
  <div style="margin: 20px;">
    <h1>项目人员分析</h1>
    <el-row :gutter="20">
      <el-col :span="8">
        <el-card>
          <div class="item">
            <span>{{ nowTime || 'Time...' }}</span>
          </div>

          <div style="text-align: center">
            现场实时人数：100 {{ x }}人<br>
            劳务总人数：10 {{ y }}人<br>
            管理人员：2{{ y1 }}人<br>
            出勤率：96{{ y1 / y }}%<br>
            普通工人：98{{ y2 }}人<br>
            出勤率：98{{ y2 / y }}%<br>
          </div>
        </el-card>

        <el-card style="height: 55%; margin-top: 20px;">
          <div>
            <span>工人信息分析</span>
            <div ref="echarts0" style="height: 280px;width: 95%;"></div>
          </div>
        </el-card>
      </el-col>

      <el-col :span="16">
        <el-card>
          <div>
            <span>工人信息分析</span>
            <div ref="echarts" style="height: 520px;width: 95%;"></div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import Monitoringbar from "@/components/Monitoringbar.vue";
import Managementbar1 from "@/components/Managementbar1.vue";
export default {
  name: "role1Monone",
  components: { Managementbar1, Monitoringbar },

  data() {
    return {
      nowTime: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      setInterval(this.showTime, 1000);
    });
    // 接下来的使用就跟之前一样，初始化图表，设置配置项
    let chart = this.$echarts.init(this.$refs.echarts)
    let charts = this.$echarts.init(this.$refs.echarts0)
    charts.setOption({
      xAxis: {

        type: 'category',

        data: ['20~30', '30~40', '40~50', '50以上']

      },

      yAxis: {

        type: 'value'

      },

      series: [

        {

          data: [50, 30, 24, 18],

          type: 'line'

        }

      ]

    });

    chart.setOption({
      title: {

        text: '工人类型',
        left: 'center'

      },

      tooltip: {

        trigger: 'item'

      },

      legend: {

        orient: 'vertical',

        left: 'left'

      },

      series: [

        {

          name: 'Access From',

          type: 'pie',

          radius: '50%',

          data: [

            { value: 1048, name: '木工' },

            { value: 735, name: '瓦工' },

            { value: 580, name: '架子工' },

            { value: 484, name: '电工' },

            { value: 300, name: '其他' }

          ],

          emphasis: {

            itemStyle: {

              shadowBlur: 10,

              shadowOffsetX: 0,

              shadowColor: 'rgba(0, 0, 0, 0.5)'

            }

          }

        }

      ]

    });
  },

  methods: {
    showTime() {
      const date = new Date();
      const year = date.getFullYear();
      let month = date.getMonth() + 1;
      console.log('====', month);
      month = month < 10 ? `0${month}` : month;
      let day = date.getDate();
      day = day < 10 ? `0${day}` : day;
      let hour = date.getHours();
      hour = hour < 10 ? `0${hour}` : hour; // 用三目运算符调整数字显示格式
      let minute = date.getMinutes();
      minute = minute < 10 ? `0${minute}` : minute;
      let second = date.getSeconds();
      second = second < 10 ? `0${second}` : second;
      // 加载现在时间
      const current = `${year}-${month}-${day} ${hour}:${minute}:${second}`;
      this.nowTime = current;
    },
  },




}


</script>

<style scoped>
.item {
  font-size: 2.0em;
  font-weight: bold;
  color: #333;
  text-align: center;
}
</style>